package com.zood.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zood.dao.StoneDao;
import com.zood.domain.stone;
import com.zood.service.IstoneService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class StoneServiceImpl extends ServiceImpl<StoneDao, stone> implements IstoneService {

    @Autowired
    private StoneDao bookDao;

    @Override
    public boolean saveBook(stone book) {
        return bookDao.insert(book) > 0;
    }

    @Override
    public boolean modify(stone book) {
        return bookDao.updateById(book) > 0;
    }

    @Override
    public boolean delete(stone stones) {
        return bookDao.delete(stones) ;
    }

    @Override
    public boolean deletebyId(Integer id) {
        return bookDao.deleteById(id) > 0;
    }


    @Override
    public IPage<stone> getPage(int currentPage, int pageSize) {
        IPage page = new Page(currentPage,pageSize);
        bookDao.selectPage(page,null);
        return page;
    }

    @Override
    public IPage<stone> getPage(int currentPage, int pageSize, stone book) {
        LambdaQueryWrapper<stone> lqw = new LambdaQueryWrapper<stone>();
 //       lqw.like(Strings.isNotEmpty(book.getVid()),stone::getVid,book.getVid());
        lqw.like(Strings.isNotEmpty(book.getSname()), stone::getSname,book.getSname());
        lqw.like(Strings.isNotEmpty(book.getSdescription()), stone::getSdescription,book.getSdescription());
        IPage page = new Page(currentPage,pageSize);
        bookDao.selectPage(page,lqw);
        return page;
    }
}
